package pkg.drowne.org;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

public class SplashScreen extends Activity {
	
		TimerTask refreshTask;
		final Handler handler = new Handler();
		Timer t = new Timer();
		
		
	    /** Called when the activity is first created. */
	    @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        requestWindowFeature(Window.FEATURE_NO_TITLE);
	        getWindow().setFlags(
	        WindowManager.LayoutParams.FLAG_FULLSCREEN,
	        WindowManager.LayoutParams.FLAG_FULLSCREEN);
	        setContentView(R.layout.splashscreen);
	        
	        // runs the splash screen for a timer
	        refreshTimer();
	        
	    }
	    
	    public void refreshTimer() {

			refreshTask = new TimerTask() {
				public void run() {
					handler.post(new Runnable() {

						public void run() {
							//Log.d("SPREAD TIMER", "SEC " + progress);
							
							refreshHandler.sendEmptyMessage(1);

						}
					});
				}
			};

			t.schedule(refreshTask, 2000);

		}
	    
	    private final Handler refreshHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				
				if (msg.what == 1) {
					
					Log.d("SPREAD TIMER", "COMPLETE");
					
					Intent newIntro = new Intent(getBaseContext(), Intro.class);
					finish();
		    		startActivity(newIntro);
					
				}
			}
		};

	    public void stopRefreshing(){

		   if(refreshTask!=null){
		      Log.d("SPREAD TIMER", "CANCELED");
		      refreshTask.cancel();
		   }
		   
	    }
}

